#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>


#define MAX_TEMP_NUM 4
static char *hwmon_name[MAX_TEMP_NUM]=
{
	"/sys/class/hwmon/hwmon1/temp1_input",
	"/sys/class/hwmon/hwmon1/temp2_input",
	"/sys/class/hwmon/hwmon1/temp3_input",
	"/sys/class/hwmon/hwmon1/temp4_input"

};
int main()
{
   int fd[MAX_TEMP_NUM];
   int i = 0;
   char buff[16];
   int j = 0;
   int count = 0;

   for(i = 0; i < MAX_TEMP_NUM; i++)
   {
        fd[i] = open(hwmon_name[i], O_RDONLY);
        if(fd[i] == -1)
        {

            printf("fd[%d] open failed\n", i);
            for(j = i - 1; j >= 0; j--)
                close(fd[j]);

            return -1;
        }
   }

   while(1)
   {
       for(int k = 0; k < MAX_TEMP_NUM; k++)
       {
           lseek(fd[k],0,SEEK_SET);
           count = read(fd[k], buff, sizeof(buff));
           if(count > 0)
	       printf("channel[%d] temp=%s\n", k, buff);

       }
      sleep(1);
   }


   for(i = 0; i < MAX_TEMP_NUM; i++)
       close(fd[i]);

}
